package com.cfs.custom;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.util.ByteSource;
import org.springframework.stereotype.Component;

import com.xiaoleilu.hutool.util.RandomUtil;

/**
 * Created by Administrator on 2017/9/26/026.
 */
@Component
public class MyRelam  extends AuthorizingRealm {


    @Override
    public void setName(String name) {
        super.setName("myRelam");
    }

    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
    	SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
    	authorizationInfo.addRole("SYS");
    	authorizationInfo.addRole("VIEW");
        return authorizationInfo;
    }

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {

        AuthenticationInfo authcInfo = new SimpleAuthenticationInfo(
               RandomUtil.randomInt() ,"xxxx",
                ByteSource.Util.bytes("123"), getName());
        return authcInfo;
    }

    @Override
    protected void assertCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) throws AuthenticationException {

    }
}
